﻿define(
	[
		"Libraries/KOWidgets/Shared/BaseKOWidget",
		"Libraries/ThirdParty/Require/text!Libraries/KOWidgets/PopupMessage/PopupMessage.html"
	], function (baseKOWidget, popupMessageControlView) {
	    $.step.BaseKOWidget.injectCssFile("Libraries_KOWidgets_PopupMessage_PopupMessage", require.toUrl("Libraries/KOWidgets/PopupMessage/PopupMessage.css"));


	    (function ($, undefined) {
	        $.widget("step.PopupMessage", $.step.BaseKOWidget,
			{
			    options: {
			        view: popupMessageControlView,
			    },

			    _createDefaultModel: function () {
			        var widgetThis = this;

			        var myViewModel = function () {
			            var self = this;
			            this.Text = ko.observable("");
			            this.Team = ko.observable([]);
			        };

			        return new myViewModel();

			    },
			    _Close: function () {
			        if (this.element.hasClass("step-PopupMessage")) {
			            this.element.removeClass("step-PopupMessage");
			        }
			        this._ClearModel();
			    },
			    _ClearModel: function () {
			        var model = this.options.model;
			        model.Text("");
			    },

			    _create: function () {
			        var self = this;

			        this._initModel();
			        this._initView();
			        this._initKO();

			        var model = this.options.model;

			        if (!this.element.hasClass("step-PopupMessage")) {
			            this.element.addClass("step-PopupMessage");
			        }

			        var address = "Address: " + this.options.address;
			        var phone = "Phone: " + this.options.phone;

			        $('#popupAddress').text(address);
			        $('#popupPhone').text(phone);

			        

			        $('#popupAddress').text(address);
			        $('#popupPhone').text(phone);

			        $('#btnYes').on('click', function () {
			            alert('Yes');
			           
			            if (self.element.hasClass("step-PopupMessage")) {
			                self.element.removeClass("step-PopupMessage");
			                $('#PopupMessage').remove();

			                self.options.res = "Yes";
			            }
			        });

			        $('#btnNo').on('click', function () {
			            alert('No');
			            
			            if (self.element.hasClass("step-PopupMessage")) {
			                self.element.removeClass("step-PopupMessage");
			                $('#PopupMessage').remove();

			                self.options.res = "No";
			            }
			        });

			        
			    },
			    SetText: function (text) {
			        var txt = text || "Default text";

			        this.options.model.Text(txt);
			    },
			    Show: function () {
			        $('.cd-popup').addClass('is-visible');
			    },
			    _setOption: function (key, value) {
			        this._handleModelViewSetOption(key, value);
			        $.Widget.prototype._setOption.apply(this, arguments);
			    }

			});
	    })(jQuery);
	    return "success - step-PopupMessage";
	}
);